package com.eastedu.superise.handler.ulearning;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.eastedu.manager.FileManager;
import com.eastedu.repository.ulearning.po.TmpFilePO;
import com.eastedu.superise.handler.AbstractHistoricalDataHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.Collections;

/**
 * 【解冻】文件归档
 *
 * @author zhangzhishuai
 */
@Slf4j
@Service
@RequiredArgsConstructor
@DS("learning")
public class LearningFileRestoreHistoricalDataHandler extends AbstractHistoricalDataHandler<TmpFilePO> {

    private final FileManager fileManager;


    @Override
    protected String getSql() {
        return "select * from t_tmp_file";
    }

    @Override
    public void callback(TmpFilePO po) throws SQLException {
        try {
            fileManager.restore(Collections.singletonList(po.getFileId()));
        } catch (Exception e) {
            log.error("{}:解冻文件信息异常：{}", po, e.getMessage(), e);
        }
    }

}
